package com.gx.smart.building.ui.knowledge.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemArticleBinding;
import com.gx.smart.lib.http.api.response.Knowledge;

/**
 * @author: xiaosy
 * 时间: 2022/4/11
 * @Description: java类作用描述
 * @Version: 1.0
 **/
public class ArticleAdapter extends BaseAdapter<Knowledge, ArticleAdapter.ViewHolder> {
    public ArticleAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_article;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemArticleBinding binding = ItemArticleBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, Knowledge item, int position) {
            holder.binding.baseTitle.setText(item.getBaseTitle());
            String createTime = TimeUtils.millis2String(item.getCreateTime(), "yyyy-MM-dd");
            holder.binding.createTime.setText(createTime);
            holder.binding.viewNumber.setText(String.valueOf(item.getViewNumber()));
    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemArticleBinding binding;

        public ViewHolder(ItemArticleBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
